#include "scheduler.h"

// 任务调度器结构体
typedef struct
{
    void (*Task_Func)(void);
    uint32_t task_interval;
    uint32_t last_run_tick;
} Task_t;

// 任务结构体数组
static Task_t sche_task[] =
{
    {Usart0_Task,  5, 0},
    {Btn_Task,     5, 0},
    {Led_Task,     1, 0}
};

static uint8_t task_num = sizeof(sche_task) / sizeof(Task_t);

// 调度函数
void Sche_Run(void)
{
    for (uint8_t i = 0; i < task_num; i++)
    {
        uint32_t now_tick = uwTick;

        if ((int32_t)(now_tick - (sche_task[i].task_interval + sche_task[i].last_run_tick)) >= 0)
        {
            sche_task[i].last_run_tick = now_tick;
            sche_task[i].Task_Func();
        }
    }
}